*** Create log file

capture log close
log using vcsn_replication_logfile.log, replace

****************
*** Voting in Clientelistic Social Networks: Evidence from the Philippines
*** Nico Ravanilla, Michael Davidson & Allen Hicken
*** September 2021
*** Version 1.0
*** Replication code
***************

/* Data accessed in this replication file:
VoterCandidateLevelData.dta
*/

*** Created in STATA/SE version 15.0

clear all
set more off

*** Install commands

*ssc install outreg2,replace

*** Change to appropriate working directory (e.g.)

cd "~/Downloads/"


*******************************
* Manuscript Tables & Figures *
*******************************


** Table 1:  Descriptive Statistics of Registered Voters of Sorsogon City

do do_tab1.do

** Table 2:  Family relationship captured in our networks.

	***Table 2 is not an empirical table; it does not need to be replicated.***
	
** Table 3:  Descriptive statistics of sampled voters of Sorsogon City

do do_tab3.do

** Table 4:  Actual candidate vote-shares as predicted by the share of voters closest to candidate.

use "CandidateLevelData.dta",clear

reg log_voteshare log_pred_voteshare, vce(cl bgy)
estimates store reg1
areg log_voteshare log_pred_voteshare, vce(cl bgy) absorb(bgy)
estimates store reg2
areg log_voteshare log_pred_voteshare bCent degree, vce(cl bgy) absorb(bgy)
estimates store reg0
areg log_voteshare log_pred_voteshare bCent degree male age no_age, vce(cl bgy) absorb(bgy)
estimates store reg4
areg log_voteshare log_pred_voteshare bCent degree male age no_age incumbent, vce(cl bgy) absorb(bgy)
estimates store reg5
areg log_voteshare log_pred_voteshare bCent degree male age no_age incumbent incumbent_lastname, vce(cl bgy) absorb(bgy)
estimates store reg6
areg log_voteshare log_pred_voteshare bCent degree male age no_age incumbent incumbent_lastname city_cand, vce(cl bgy) absorb(bgy)
estimates store reg7
outreg2 [reg1 reg2 reg0 reg4 reg5 reg6 reg7] using  "tab4.xls",replace auto(2)

** Table 5:  Vote shares and candidate favorability ratings, by electoral race.

do do_tab5.do

** Table 6:  The effect of familial distance on candidate favorability ratings.

use "VoterCandidateLevelData.dta",clear

reg favorite sd sd2, vce(cl id_survey)
estimates store reg1

reg favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat, vce(cl id_survey)
estimates store reg2

reg favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3, vce(cl id_survey)
estimates store reg3

reg favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand_degree cand_bcent ///
cand_mm cand_vm cand_cc cand_male cand_age cand_no_age cand_incumbent cand_incumbent_lastname, vce(cl id_survey)
estimates store reg4

reg favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up ///
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg5

areg favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey) absorb(id_survey)
estimates store reg6

outreg2 [reg1 reg2 reg3 reg4 reg5 reg6] using  "tab6.xls",replace auto(2)

** Table 7:  The effect of familial distance on the probability of supporting a candidate at the polls.

use "VoterCandidateLevelData.dta",clear

reg vote favorite sd sd2, vce(cl id_survey)
estimates store reg1

reg vote favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat, vce(cl id_survey)
estimates store reg2

reg vote favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3, vce(cl id_survey)
estimates store reg3

reg vote favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand_degree cand_bcent ///
cand_mm cand_vm cand_cc cand_male cand_age cand_no_age cand_incumbent cand_incumbent_lastname, vce(cl id_survey)
estimates store reg4

reg vote favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up ///
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg5

areg vote favorite sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey) absorb(id_survey)
estimates store reg6

outreg2 [reg1 reg2 reg3 reg4 reg5 reg6] using  "tab7.xls",replace auto(2)

** Figure 1:  Degree distribution of individuals in the barangay-level networks

***************Please see Analysis_BonotFigure.R file

** Figure 2:  Barangay Mahangin Family Network

***************Please see Analysis_BonotFigure.R file

** Figure 3:  The relationship between the predicted number of votes and 
**the actual numbercandidates running for barangay (left) and municipal office (right) received.

***************Please see Analysis_CandidateLevel.R file

** Figure 4: The effect of familial distance on candidate favorability ratings.

areg favorite i.sd male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey) absorb(id_survey)

margins, at(sd=(1(1)5)) ///
plot(recast(line) recastci(rarea) ciopts(fcolor(ltblue%80) fintensity(50) ///
lwidth(none)) ytitle( Candidate favorability ratings with 95% CI) ///
ytitle(, size(small)) yline(0, lwidth(thin) lpattern(dash) lcolor(red)) ///
ylabel(, labsize(small) angle(horizontal)) xtitle(Familial Distance) ///
xtitle(, size(small)) xlabel(1(1)5, labsize(small)) ///
title(The effect of familial distance on candidate favorability ratings) name(fig4, replace))
graph save fig4.pdf, replace

** Figure 5: The effect of familial distance on the probability of supporting a candidate at the polls.

areg vote favorite i.sd male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up  ///
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey) absorb(id_survey)

margins, at(sd=(1(1)5)) ///
plot(recast(line) recastci(rarea) ciopts(fcolor(ltblue%80) fintensity(50) ///
lwidth(none)) ytitle(Probability of supporting a candidate at the polls with 95% CI) ///
ytitle(, size(small)) yline(0, lwidth(thin) lpattern(dash) lcolor(red)) ///
ylabel(, labsize(small) angle(horizontal)) xtitle(Familial Distance) ///
xtitle(, size(small)) xlabel(1(1)5, labsize(small)) ///
title(The effect of familial distance on the probability of supporting a candidate at the polls) name(fig5, replace))
graph save fig5.pdf, replace

** Figure 6: How the effect of vote-buying perceptions on vote-switching varies by familial  distance.

areg switched_away sd##sd male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey) absorb(id_survey)

margins, at(sd=(1(1)5)) ///
plot(recast(line) recastci(rarea) ciopts(fcolor(ltblue%80) fintensity(50) ///
lwidth(none)) ytitle(Marginal Effect on Vote-Buying Targeting with 95% CI) ///
ytitle(, size(small)) yline(0, lwidth(thin) lpattern(dash) lcolor(red)) ///
ylabel(, labsize(small) angle(horizontal)) xtitle(Social Network Density) ///
xtitle(, size(small)) xlabel(1(1)5, labsize(small)) ///
title(Degree Centrality) name(fig6, replace))
graph save fig6.pdf, replace


*******************************************
* Supporting Information Tables & Figures *
*******************************************

** Table A.1:  The effect of familial distance and vote-buying perceptions 
** on vote-switching in the run-up to elections.

gen frm_sd= fract_recd_money*sd
gen frm_sd2= fract_recd_money*sd2

reg switched_away sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg1

reg switched_away fract_recd_money male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg2


reg switched_away fract_recd_money frm_sd frm_sd2 sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg0

reg switched_into sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg4

reg switched_into fract_recd_money male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg5

reg switched_into fract_recd_money frm_sd frm_sd2 sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up  ///
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg6

outreg2 [reg2 reg1 reg0 reg5 reg4 reg6] using  "tabA1.xls",replace auto(2)

** Table A.2:  The effect of familial distance on the probability of supporting 
** a candidate at the polls (without controlling for initial favorability ratings).

reg vote sd sd2, vce(cl id_survey)
estimates store reg1

reg vote sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat, vce(cl id_survey)
estimates store reg2

reg vote sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3, vce(cl id_survey)
estimates store reg3

reg vote sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand_degree cand_bcent ///
cand_mm cand_vm cand_cc cand_male cand_age cand_no_age cand_incumbent cand_incumbent_lastname, vce(cl id_survey)
estimates store reg4

reg vote sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up ///
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey)
estimates store reg5

areg vote sd sd2 male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up /// 
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey) absorb(id_survey)
estimates store reg6

outreg2 [reg1 reg2 reg3 reg4 reg5 reg6] using  "tabA2.xls",replace auto(2)

** Table A.3:  Summary statistics for the main variables used in Tables 6 and 7.

do do_tabA3.do

** Figure  A.1: The effect of familial distance on the probability of supporting a candidate at the polls;
** mayoral and vice-mayoral candidates only.

preserve

keep if executive==1

areg vote favorite i.sd male age catholic hh_voting_mems ///
employ_stat1 employ_stat2 employ_stat3 employ_stat4 o.employ_stat5 employ_stat6 ///
elementary some_highschool highschool some_college vocational college_up  ///
o.bornhere childmigrant adultmigrant ///
i.marital_stat o.dist1 dist2 dist3 ///
cand1-cand41, vce(cl id_survey) absorb(id_survey)


margins, at(sd=(1(1)5)) ///
plot(recast(line) recastci(rarea) ciopts(fcolor(ltblue%80) fintensity(50) ///
lwidth(none)) ytitle(Probability of supporting a candidate at the polls with 95% CI) ///
ytitle(, size(small)) yline(0, lwidth(thin) lpattern(dash) lcolor(red)) ///
ylabel(, labsize(small) angle(horizontal)) xtitle(Familial Distance) ///
xtitle(, size(small)) xlabel(1(1)5, labsize(small)) ///
title(The effect of familial distance on the probability of supporting a candidate at the polls) name(fig5, replace))
graph save figA1.pdf, replace

restore

log close
